package com.example.administrator.xiaobo.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.xiaobo.R;
import com.example.administrator.xiaobo.adapter.show_adapter.ShowAdapter1;
import com.example.administrator.xiaobo.adapter.show_adapter.ShowAdapter2;
import com.example.administrator.xiaobo.adapter.show_adapter.ShowAdapter3;
import com.example.administrator.xiaobo.adapter.show_adapter.ShowAdapter4;
import com.example.administrator.xiaobo.adapter.show_adapter.ShowAdapter5;
import com.example.administrator.xiaobo.bean.show_3Bean;
import com.example.administrator.xiaobo.bean.show_5Bean;
import com.example.administrator.xiaobo.bean.show_6Bean;
import com.example.administrator.xiaobo.bean.show_9Bean;
import com.example.administrator.xiaobo.bean.show_Bean;
import com.example.administrator.xiaobo.holder.ShowViewHolder1;
import com.example.administrator.xiaobo.holder.ShowViewHolder2;

import java.util.LinkedList;

/**
 * Created by Administrator on 2017/2/8.
 */

public class ShowRecyclerAdapter extends RecyclerView.Adapter {
    private Context context;
    private LinkedList<show_Bean> data;
    public ShowRecyclerAdapter(Context context,LinkedList<show_Bean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getItemViewType(int position) {
        return data.get(position).viewType;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType==2||viewType==3||viewType==1) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_show_01,null);
            TextView textView = (TextView) view.findViewById(R.id.textView_show_01);
            RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.relativeLayout);
            TextView textView1 = (TextView) view.findViewById(R.id.filter);
            if (viewType == 3) {
                textView.setVisibility(View.INVISIBLE);
            }else
                textView.setVisibility(View.VISIBLE);
            if (viewType != 1) {
                relativeLayout.setVisibility(View.GONE);
            }else
                relativeLayout.setVisibility(View.VISIBLE);
            return new ShowViewHolder1(view);
        }else{
            View view = LayoutInflater.from(context).inflate(R.layout.item_show_02,null);
            ImageView imageView = (ImageView) view.findViewById(R.id.imageView_show02);
            TextView textView = (TextView) view.findViewById(R.id.more_show02);
            if (viewType == 9||viewType == 5) {
                if (viewType == 5) {
                    textView.setVisibility(View.INVISIBLE);
                }else
                    textView.setVisibility(View.VISIBLE);
                imageView.setVisibility(View.GONE);
            }else{
                textView.setVisibility(View.VISIBLE);
                imageView.setVisibility(View.VISIBLE);
            }
            return new ShowViewHolder2(view);
        }

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        switch (getItemViewType(position)){
            case 1:
                if (holder instanceof ShowViewHolder1) {
                    GridLayoutManager gridLayoutManager = new GridLayoutManager(context,5);
                    gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
                    ((ShowViewHolder1) holder).recyclerView.setLayoutManager(gridLayoutManager);
                    ShowAdapter1 adapter = new ShowAdapter1(context,data.get(position));
                    ((ShowViewHolder1) holder).recyclerView.setAdapter(adapter);
                }
                break;
            case 2:
                if (holder instanceof ShowViewHolder1) {
                    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context) ;
                    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                    ((ShowViewHolder1) holder).recyclerView.setLayoutManager(linearLayoutManager);
                    ShowAdapter1 adapter = new ShowAdapter1(context,data.get(position));
                    ((ShowViewHolder1) holder).recyclerView.setAdapter(adapter);
                }
                break;
            case 3:
                if (holder instanceof ShowViewHolder1) {
                    GridLayoutManager gridLayoutManager = new GridLayoutManager(context,5);
                    gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
                    ((ShowViewHolder1) holder).recyclerView.setLayoutManager(gridLayoutManager);
                    ShowAdapter2 adapter = new ShowAdapter2(context,((show_3Bean)data.get(position)).list);
                    ((ShowViewHolder1) holder).recyclerView.setAdapter(adapter);
                }
                break;
            case 4:
                break;
            case 5:
                if (holder instanceof ShowViewHolder2) {
                    show_5Bean show_5Bean = (com.example.administrator.xiaobo.bean.show_5Bean) data.get(position);
                    ((ShowViewHolder2) holder).title.setText("今日推荐");
                    GridLayoutManager gridLayoutManager = new GridLayoutManager(context,3);
                    gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
                    ((ShowViewHolder2) holder).recyclerView.setLayoutManager(gridLayoutManager);
                    ShowAdapter5 adapter = new ShowAdapter5(context,show_5Bean.list);
                    ((ShowViewHolder2) holder).recyclerView.setAdapter(adapter);
                }
                break;
            case 6:
                if (holder instanceof ShowViewHolder2) {
                    show_6Bean show_6Bean = (com.example.administrator.xiaobo.bean.show_6Bean) data.get(position);
                    Glide.with(context).load(show_6Bean.level1).into(((ShowViewHolder2) holder).imageView);
                    ((ShowViewHolder2) holder).title.setText(show_6Bean.name);
                    GridLayoutManager gridLayoutManager = new GridLayoutManager(context,3);
                    gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
                    ((ShowViewHolder2) holder).recyclerView.setLayoutManager(gridLayoutManager);
                    ShowAdapter3 adapter = new ShowAdapter3(context,show_6Bean.list);
                    ((ShowViewHolder2) holder).recyclerView.setAdapter(adapter);
                }
                break;
            case 9:
                if (holder instanceof ShowViewHolder2) {
                    show_9Bean show_9Bean = (com.example.administrator.xiaobo.bean.show_9Bean) data.get(position);
                    ((ShowViewHolder2) holder).title.setText("主播热舞合集");
                    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
                    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                    ((ShowViewHolder2) holder).recyclerView.setLayoutManager(linearLayoutManager);
                    ShowAdapter4 adapter = new ShowAdapter4(context,show_9Bean.list);
                    ((ShowViewHolder2) holder).recyclerView.setAdapter(adapter);
                }
        }

    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}
